/* pfs01Login.cpp
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#include <packet/pfs01Login.h>
#include <wrapper/JavaStreamWrapper.h>

pfs01Login::pfs01Login()
    : McPacketFromServer(0x01), pid(0), unused1(""), seed(0), type(""), mode(0), dimension(0), difficulty(0), height(0), maxplayers(0)
{
}

unsigned int pfs01Login::length()
{
    return 1 + 4 + 2 + 8 + 2 + 4 + 1 + 1 + 1 + 1 + type.length();
}

int16_t pfs01Login::setField(uint8_t field, void* value)
{
    static int16_t slen;

    switch (field)
    {
        case 0:
        default: return 4;
        case 1: pid = JavaStreamWrapper::readInt(value); return 2;
        case 2: slen = JavaStreamWrapper::readShort(value); return 2*slen;
        case 3: unused1 = JavaStreamWrapper::readUTF(value, slen); return 8;
        case 4: seed = JavaStreamWrapper::readLong(value); return 2;
        case 5: slen = JavaStreamWrapper::readShort(value); return 2*slen;
        case 6: type = JavaStreamWrapper::readUTF(value, slen); return 4;
        case 7: mode = JavaStreamWrapper::readInt(value); return 1;
        case 8: dimension = JavaStreamWrapper::readByte(value); return 1;
        case 9: difficulty = JavaStreamWrapper::readByte(value); return 1;
        case 10: height = JavaStreamWrapper::readUnsignedByte(value); return 1;
        case 11: maxplayers = JavaStreamWrapper::readUnsignedByte(value); return -1;
    }
}

int32_t pfs01Login::getPid()
{
    return pid;
}

std::string pfs01Login::getUnused1()
{
    return unused1;
}

int64_t pfs01Login::getSeed()
{
    return seed;
}

std::string pfs01Login::getType()
{
    return type;
}

int32_t pfs01Login::getMode()
{
    return mode;
}

int8_t pfs01Login::getDimension()
{
    return dimension;
}

int8_t pfs01Login::getDifficulty()
{
    return difficulty;
}

uint8_t pfs01Login::getHeight()
{
    return height;
}

uint8_t pfs01Login::getMaxplayers()
{
    return maxplayers;
}


